/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.lis.ctrl;

import com.cxhd.lis.model.newmodel.LisCharginitem;
import static com.cxhd.lis.model.newmodel.LisCharginitem.lisCharginitemdao;
import com.cxhd.lis.model.newmodel.LisDeviceset;
import static com.cxhd.lis.model.newmodel.LisDeviceset.lisDevicesetdao;
import com.jfinal.core.Controller;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import java.util.List;

/**
 *
 * @author cxhd
 */
@ControllerBind(controllerKey = "/view/lis/citem")
public class LisCharginitemCtrl extends Controller{
     public void index(){
        render("/view/lis/sfxmwh.jsp");
    }
      public void getLisCharginitem(){// 待加分页
//        renderJson(Db.use("mysql").find("select * from lis_charginitem LIMIT 0,10"));
      String sql="select PK,ITEMID,ITEMNAME,PRICE,DATA1";
     String param=" from lis_charginitem where ITEMID like '%"+getPara("searchContent")+"%' or ITEMNAME like '%"+getPara("searchContent")+"%'";
Page<Record> userPage = Db.use("mysql").paginate(getParaToInt("currentPage",getParaToInt("currentPage")), getParaToInt("pageSize", getParaToInt("pageSize")), sql, param);
renderJson(userPage);
    }
    public void  getLisCharginitemRep(){
         List<Record> list= Db.use("mysql").find("select * FROM lis_charginitem WHERE ITEMNAME=?",getPara("ITEMNAME"));
       if(list.size()!=0){ 
            if(getPara("PK")!=""&&getPara("PK")!=null){//判断是新增还是修改
                if(Integer.valueOf(getPara("PK"))==list.get(0).get("PK")){ //修改是允许修改（本身主键和查询到的主键相同）
                     renderText("false");
                }else{
                   renderText("true");  
                }
            }else{
                renderText("true");
            }
        
        }else{
            renderText("false");
        }
    }
    public void deleteLisCharginitem(){
        lisCharginitemdao.deleteLisCharginitem(getPara("PK"));
        renderText("true");
    }  
    public void saveLisCharginitem(){
        new LisCharginitem().saveLisCharginitem(getPara("ITEMNAME"),getPara("PRICE"));
        renderText("true");
    }
    public void updateLisCharginitem(){
        lisCharginitemdao.updateLisCharginitem(getPara("PK"), getPara("ITEMNAME"),getPara("PRICE"));
        renderText("true");
    }
}
